<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" value="100" id="input1">
		<button onclick="test1()">开启定时执行</button>
		<button onclick="test2()">关闭定时执行</button>
		
		<script type="text/javascript">
			
			var t;
			// setInterval(定时要执行的代码,定时的时间)
			function test1()
			{
				t=setInterval(changeBgColor,input1.value);
			}
			// clearInterval  清除定时
			function test2()
			{
				clearInterval(t);
			}
			
			function changeBgColor()
			{
				var r = Math.floor(Math.random()*256);
				var g = Math.floor(Math.random()*256);
				var b = Math.floor(Math.random()*256);
				document.body.style.background = "rgb("+r+","+g+","+b+")"
			}
			
			// 练习3:
			// 编写一个时钟，显示当前时间，定时刷新
			
		</script>

		
	</body>
</html>
